package com.tanglongan.designPattern.dp06_adapter.demo03.optimize01;

import com.tanglongan.designPattern.dp06_adapter.demo03.IPasswordForThird;
import com.tanglongan.designPattern.dp06_adapter.demo03.oldSystem.PasswordService;
import com.tanglongan.designPattern.dp06_adapter.demo03.oldSystem.ResultMsg;

/**
 * 实现对外目标接口，并且继承原系统接口进行包装
 */
public class PasswordForThirdAdapterV1 extends PasswordService implements IPasswordForThird {

    @Override
    public ResultMsg loginForQQ(String openId) {
        return this.loginForRegist(openId, null);
    }

    @Override
    public ResultMsg loginForWeChat(String openId) {
        return this.loginForRegist(openId, null);
    }

    @Override
    public ResultMsg loginForToken(String openId) {
        return this.loginForRegist(openId, null);
    }

    @Override
    public ResultMsg loginForTelphone(String phone, String code) {
        return this.loginForRegist(phone, null);
    }


    private ResultMsg loginForRegist(String username, String password) {
        if (password == null) {
            password = "THIRD_EMPTY";
        }
        super.register(username, password);
        return super.login(username, password);
    }
}
